home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 2002 Tom Parker (tom@carrott.org),
- Matthias Münch (matthias@amigaworld.de)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- In addition, as a special exception, Tom Parker and Matthias Münch give
- permission to link the code of this program with a TCP stack of your
- choice, any official MUI libraries or classes and any custom MUI classes
- that should be necessary for the operation of this program. This
- exception also gives you permission to distribute linked combinations
- including this software with any of the before-mentioned libraries and
- classes. You must obey the GNU General Public License in all respects for
- all of the code used other than that provided by the before-mentioned
- libraries and classes. As part of this exception you are obliged to
- follow the license terms of the before-mentioned libraries, this license
- does not compel you to follow those terms, but if you do not then you may
- not link with those libraries. If you modify this file, you may extend
- this exception to your version of the file, but you are not obligated to
- do so. If you do not wish to do so, delete this exception statement from
- your version.
- */
- /*
- ** message compose window
- */
-
- #include "common.h"
-
- #include <MUI/TextEditor_mcc.h>
-
- ULONG write_new(struct IClass *cl, Object *obj, struct opSet *msg);
- void write_send(Object *obj, struct writedata *data);
-
-
- MUI_DISPATCH(write_dispatch)
- {
- switch(msg->MethodID)
- {
- case OM_NEW:
- return write_new(cl,obj,(APTR)msg);
-
- case WRITE_SEND:
- write_send(obj, INST_DATA(cl,obj));
- return(0);
-
-
- }
- return(DoSuperMethodA(cl,obj,msg));
- }
-
-
- ULONG write_new(struct IClass *cl, Object *obj, struct opSet *msg)
- {
- struct writedata *data;
- Object *tostr, *substr, *texted, *slider, *sendbut, *canbut;
- char *user, *thread, *body;
-
- obj = (Object *)DoSuperNew(cl,obj,
- MUIA_Window_Title, MSG_WRITE_MESSAGE_TITLE,
- MUIA_HelpNode, "window-writemsg",
- WindowContents, VGroup,
- Child, ColGroup(2),
- Child, Label2(MSG_WRITE_TO),
- Child, (ULONG) tostr = StringObject,
- StringFrame,
- MUIA_String_AdvanceOnCR, TRUE,
- MUIA_CycleChain, 1,
- End,
- Child, Label2(MSG_WRITE_THREAD),
- Child, (ULONG) substr = StringObject,
- StringFrame,
- MUIA_String_AdvanceOnCR, TRUE,
- MUIA_CycleChain, 1,
- End,
- End,
- Child, HGroup,
- Child, (ULONG) texted = TextEditorObject,
- MUIA_CycleChain, 1,
- End,
- Child, (ULONG) slider = ScrollbarObject,
- End,
- End,
- Child, HGroup,
- Child, (ULONG) sendbut = SimpleButton(MSG_WRITE_SEND_GAD),
- Child, (ULONG) canbut = SimpleButton(MSG_WRITE_CANCEL_GAD),
- End,
- End,
- TAG_MORE, msg->ops_AttrList);
-
- if(!obj) return(0);
-
- set(texted, MUIA_TextEditor_Slider, (ULONG) slider);
-
- user = (char *)GetTagData(WRITE_TO, NULL, msg->ops_AttrList);
- thread = (char *)GetTagData(WRITE_THREAD, NULL, msg->ops_AttrList);
- body = (char *)GetTagData(WRITE_QUOTE, NULL, msg->ops_AttrList);
-
- user = iks_strdup(convert_locale(user));
- body = iks_strdup(convert_locale(body));
- thread = iks_strdup(convert_locale(thread));
-
- if (user) {
- set(tostr, MUIA_String_Contents, (ULONG) user);
- }
- if (thread) {
- set(substr, MUIA_String_Contents, (ULONG) thread);
- }
- if (body) {
- set(texted, MUIA_TextEditor_Contents, (ULONG) body);
- }
-
- data = INST_DATA(cl,obj);
- data->tostr = tostr;
- data->substr = substr;
- data->texted = texted;
-
-
- DoMethod(sendbut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, WRITE_SEND);
-
- DoMethod(canbut, MUIM_Notify, MUIA_Pressed, FALSE, MUIV_Notify_Application, 5, MUIM_Application_PushMethod, gui.list, 2, ROSTER_CLOSEME, obj);
- DoMethod(obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, MUIV_Notify_Application, 5, MUIM_Application_PushMethod, gui.list, 2, ROSTER_CLOSEME, obj);
-
- free(user);
- free(body);
- free(thread);
-
- return((ULONG)obj);
- }
-
-
- void write_send(Object *obj, struct writedata *data)
- {
- char *to, *sub, *text;
- iks *x;
-
- if(net.state != NET_ON)
- {
- printf("not connected yet!\n");
- DoMethod(gui.app, MUIM_Application_PushMethod, gui.list, 2, ROSTER_CLOSEME, obj);
- return;
- }
-
- to = mui_sget(data->tostr);
- sub = mui_sget(data->substr);
- text = (char *)DoMethod(data->texted, MUIM_TextEditor_ExportText);
-
- if(to)
- {
- to = strdup(convert_utf8(to));
- if (sub) {
- sub = strdup(convert_utf8(sub));
- }
- x = iks_make_msg(IKS_TYPE_NONE, to, convert_utf8(text), sub);
- iks_send(net.parser, x);
- iks_delete(x);
- free(to);
- if (sub) {
- free(sub);
- }
- }
-
-
- FreeVec(text);
- DoMethod(gui.app, MUIM_Application_PushMethod, gui.list, 2, ROSTER_CLOSEME, obj);
- }
-
-
- void write_to(char *to, char *thread, char *body)
- {
- Object *win;
-
- win = NewObject(gui.write_mcc->mcc_Class, NULL, WRITE_TO, (ULONG) to, WRITE_THREAD, (ULONG) thread, WRITE_QUOTE, (ULONG) body, TAG_DONE);
- if(win) {
- DoMethod(gui.app, OM_ADDMEMBER, win);
- set(win, MUIA_Window_Open, TRUE);
- }
- }
-